package com.haiwei.poi.word.poi;

import com.haiwei.poi.common.HaiweiListUtils;
import com.haiwei.poi.word.loop.HaiweiRowGroup;
import com.haiwei.poi.word.loop.HaiweiRowGroupUtil;
import com.haiwei.poi.word.loop.HaiweiTable;
import com.haiwei.poi.word.loop.HaiweiTableUtil;
import org.apache.poi.xwpf.usermodel.*;

import java.util.List;

/**
 * XWPFDocument 工具类.
 *
 * @date: 2022-06-27
 * @version: 1.0
 * @author: karry@haiwei.com
 */
public class HaiweiXWPFDocumentUtil {
    
    /**
     * 解析文本
     * @param document
     */
    public static void parse(XWPFDocument document) {
        // 页眉
        final List<XWPFHeader> headerList = document.getHeaderList();
        if(HaiweiListUtils.isNotBlank(headerList)){
            for(XWPFHeader header : headerList){
                HaiweiParagraphUtil.pause(header.getParagraphs());
                HaiweiXWPFTableUtil.parseTable(header.getTables());
            }
        }
        
        // 页脚
        final List<XWPFFooter> footerList = document.getFooterList();
        if(HaiweiListUtils.isNotBlank(footerList)){
            for(XWPFFooter footer : footerList){
                HaiweiParagraphUtil.pause(footer.getParagraphs());
                HaiweiXWPFTableUtil.parseTable(footer.getTables());
            }
        }
        
        // 处理
        List<XWPFParagraph> paragraphs = document.getParagraphs();
        HaiweiParagraphUtil.pause(paragraphs);
        
        // 表格
        HaiweiXWPFTableUtil.parseTable(document.getTables());
    }
    
}
